import axios from 'axios';
import { ElLoading } from 'element-plus'; //引入加载动画
// 定义加载动画
let loading = '';
const startLoading = () => {
        const options = {
            lock: true,
            text: "加载中...",
            backgroud: "rbga(0,0,0,0.7)"
        }
        loading = ElLoading.service(options);
    }
    // 结束 loding
const EndLoading = () => {
        loading.close()
    }
    //  请求拦截
axios.interceptors.request.use(config => {
        // config.headers.ContentType = 'application/json'
        config.headers.Authorization = window.localStorage.getItem('token');
        startLoading()
        return config
    })
    // 响应拦截
axios.interceptors.response.use(response => {
    EndLoading()
    return response
}, error => {
    return Promise.reject(error)
    EndLoading()
})
export default axios